<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jsp:include page="/WEB-INF/jsp/common/common.jsp" />
<jsp:include page="/WEB-INF/jsp_lib/validate.jsp" />
<jsp:include page="/WEB-INF/jsp_lib/layer.jsp" />
<script type="text/javascript"
	src="${path}/style_lib/upload/swfupload/swfupload.js"></script>
<script type="text/javascript"
	src="${path}/style_lib/upload/swfupload/fileprogress.js"></script>
<script type="text/javascript"
	src="${path}/style_lib/upload/swfupload/handlers.js"></script>
<script type="text/javascript">
	var click_id;
	$(function() {
		$("select[name='mac_id']").val("${apply.mac_id}");
		$("select[name='seal_id']").val("${apply.seal_id}");
		$("select[name='is_out']").val("${apply.is_out}");
		$("select[name='use_type']").val("${apply.use_type}");
		$("#form1").validate({
			ignore : [],
			rules : {
				'reason' : {
					required : true
				},
				'copes' : {
					required : true,
					digits : true
				},
				'num' : {
					required : true,
					digits : true
				},
				'apply_user_name' : {
					required : true
				},
				'apply_department' : {
					required : true
				},
				'type_name' : {
					required : true
				},
				'word_name' : {
					required : true
				},
				'seal_id' : {
					required : true
				}
			}
		});
		$("#emp").hide();
	});
	function uploadSuccess(file, serverData) {
		var end = $.parseJSON(serverData);
		var str = end.file_name;
		var id = end.file_id;
		$("#emp").hide();
		$("#empScan").hide();
		var obj_id = $("input[name=" + click_id + "]");
		var obj_name = $("#" + click_id);
		if (obj_id.val() == "" || obj_id.val() == null) {
			obj_id.val(id);
		} else {
			obj_id.val(obj_id.val() + "," + id);
		}
		var del_mark = " <a href=\"javascript:delFile('@id','@str','@click_id')\"><img alt='删除' src='${path }/style_cp/icons/httrash.gif'/></a>";
		del_mark = del_mark.replace("@id", id);
		del_mark = del_mark.replace("@str", str);
		del_mark = del_mark.replace("@click_id", click_id);
		if (obj_name.html() == "" || obj_name.html() == null) {
			obj_name.html("<span id="+id+">" + str + del_mark + "</span");
		} else {
			obj_name.html(obj_name.html() + "		" + "<span id="+id+">" + str
					+ del_mark + "</span");
		}
	}
	$(function() {
		new SWFUpload(
				{

					// Backend Settings
					upload_url : "${path}/swfupload.htm",
					//post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
					// File Upload Settings
					file_size_limit : "1200 MB", // 100MB
					file_types : "*.gif;*.jpg;*.jpeg;*.bmp;*.png;*.txt;*.doc;*.xls;*.pdf;*.ppt;*.docx;*.xlsx;*.pptx;*.rar;*.zip",
					file_upload_limit : 10,
					file_queue_limit : 10,

					// Event Handler Settings (all my handlers are in the Handler.js file)
					swfupload_preload_handler : preLoad,
					swfupload_load_failed_handler : loadFailed,
					file_dialog_start_handler : fileDialogStart,
					file_queued_handler : fileQueued,
					file_queue_error_handler : fileQueueError,
					file_dialog_complete_handler : fileDialogComplete,
					upload_start_handler : uploadStart,
					upload_progress_handler : uploadProgress,
					upload_error_handler : uploadError,
					upload_success_handler : uploadSuccess,
					upload_complete_handler : uploadComplete,

					// Button Settings
					button_placeholder_id : "file_ids",
					button_width : 80,
					button_height : 22,
					button_text : "上传附件",

					// Flash Settings
					flash_url : "${path}/style_lib/upload/swfupload/swfupload.swf",
					flash9_url : "${path}/style_lib/upload/swfupload/swfupload_fp9.swf",

					custom_settings : {
						progressTarget : "fsUploadProgress1"//,
					//cancelButtonId : "btnCancel1"
					},

					// Debug Settings
					debug : false
				});
	});
	//下拉 印章类型,弹出印章种类
	function mysubmit() {
		$("#form1").submit();
	}
	function addFiles(msg, id) {
		click_id = id;
		$("#msg").html(msg);
		$("#emp").show();
	}
	function delFile(id, name, click_id) {
		var obj_id = $("input[name=" + click_id + "]").val() + "";
		var obj_name = $("#" + click_id).html() + "";
		obj_id = obj_id.replace(id, " ");
		obj_name = obj_name.replace(name, "");
		$("input[name=" + click_id + "]").val(obj_id);
		$("#" + click_id).html(obj_name);
		$("#" + id).hide();
	}
	function hideDiv() {
		$("#emp").hide();
	}
</script>
</head>
<body>
	<jsp:include page="/WEB-INF/jsp_lib/tip.jsp" />
	<jsp:include page="/WEB-INF/jsp/common/select_user.jsp" />
	<jsp:include page="/WEB-INF/jsp/common/select_type.jsp" />
	<jsp:include page="/WEB-INF/jsp/common/select_word.jsp" />
	<!-- 内容 -->
	<div>
		<form method="post" action="${path}/ix/useapply/apply/edit.htm"
			id="form1">
			<input name='apply_id' type="hidden" value="${apply._id }" />
			<h2>
				<div>印章使用申请</div>

			</h2>
			<table width="100%" class="lindex">
				<tr>
					<th align="right" style="min-width: 100px;">用印事由</th>
					<td align="left"><input name="reason" type="text"
						style="width:400px;" maxlength="255" value="${apply.reason }" /></td>
					<th align="right">主送单位</th>
					<td align="left"><input name="company" type="text"
						maxlength="200" value="${apply.company }" /></td>
				</tr>

				<tr>
					<th align="right">印章仪名称</th>
					<td align="left"><select name="mac_id">
							<option value="">--请选择--</option>
							<c:forEach items="${macList}" var="v">
								<option value="${v._id}">${v.code}</option>
							</c:forEach>
					</select></td>

					<th align="right">印章名称</th>
					<td align="left"><select name="seal_id">
							<option value="">--请选择--</option>
							<c:forEach items="${sealList}" var="v">
								<option value="${v._id}">${v.name}(${v.true_code})</option>
							</c:forEach>
					</select></td>
				</tr>
				<tr>
					<th align="right">对外用印</th>
					<td align="left"><select name="is_out">
							<option value="否">否</option>
							<option value="是">是</option>
					</select></td>
					<th align="right">用印方式</th>
					<td align="left"><select name="use_type">
							<option value="柜员自主用印">柜员自主用印</option>
							<option value="本地验密用印">本地验密用印</option>
							<option value="远程验密用印">远程验密用印</option>
					</select></td>
				</tr>
				<tr>
					<th align="right">用印份数</th>
					<td align="left"><input name="copes" type="text"
						maxlength="10" value="${apply.copes }" /></td>
					<th align="right">盖章数/份</th>
					<td align="left"><input name="num" type="text" maxlength="10"
						value="${apply.num }" /></td>
				</tr>
				<tr>
					<th align="right">申请人</th>
					<td align="left"><input name="apply_user" type="hidden"
						value="${apply.apply_user }" /> <input name="apply_user_name"
						readonly="readonly" onClick="getUser();" style="width:300px"
						value="${user.uname }" type="text" maxlength="100" /> <a
						href="javascript:getUser()"><img alt="请选择申请人"
							src="${path }/style_cp/img/02.gif" /></a></td>
					<th align="right">发起人</th>
					<td align="left"><input name="promoter" type="text"
						readonly="readonly" value="${apply.promoter }" /></td>
				</tr>
				<tr>
					<th align="right">申请部门</th>
					<td align="left"><input name="apply_department"
						style="width:300px" type="text" maxlength="100"
						value="${apply.apply_department }" /></td>
					<th align="right">申请时间</th>
					<td align="left"><input name="apply_time" type="text"
						readonly="readonly" value="${apply.apply_time }" /></td>
				</tr>
				<tr>
					<th align="right">申请事由<br />具体描述
					</th>
					<td align="left" colspan="3"><textarea name="note" type="text"
							maxlength="255" rows="3" cols="60">${apply.note }</textarea></td>
				</tr>
				<tr>
					<th align="right">办公室意见</th>
					<td align="left"></td>
					<th align="right">行长意见</th>
					<td align="left"></td>
				</tr>
				<tr>
					<th align="right">主题词</th>
					<td align="left" colspan="3">类别词：<input name="type_name"
						readonly="readonly" onClick="getType();" style="width:300px"
						value="${apply.type_name }" type="text" maxlength="100" /> <a
						href="javascript:getType()"><img alt="请选择主题词"
							src="${path }/style_cp/img/02.gif" /></a> 文种词：<input
						name="word_name" readonly="readonly" onClick="getWord();"
						style="width:300px" value="${apply.word_name }" type="text"
						maxlength="100" /> <a href="javascript:getWord()"><img
							alt="请选择文种词" src="${path }/style_cp/img/02.gif" /></a>
					</td>
				</tr>
				<tr>
					<th align="right">注解</th>
					<td align="left" colspan="3"><textarea name="other_note"
							type="text" maxlength="255" rows="2" cols="60">${apply.other_note }</textarea></td>
				</tr>
				<tr>
					<th align="right">用印申请附件</th>
					<td align="left" colspan="3"><span id="apply_file_ids">
							<c:forEach items="${files.apply_files}" var="m">
								<span id='${m._id}'> <a
									href="${path }/download/${m._id}.htm"
									style="margin-right: 10px;">${m.file_name} </a> <a
									href="javascript:delFile('${m._id }','${m.file_name}','apply_file_ids')"><img
										alt='删除' src='${path }/style_cp/icons/httrash.gif' /> </a>
								</span>
							</c:forEach>
					</span> <input type="hidden" name="apply_file_ids"
						value="${apply.apply_file_ids }" />
						<button type="button"
							onclick="addFiles('用印申请附件','apply_file_ids')">上传附件</button>
						<button type="button"
							onclick="addScanFiles('用印申请附件','apply_file_ids')">扫描上传附件</button>
					</td>
				</tr>
				<tr>
					<th align="right">部门审查附件</th>
					<td align="left" colspan="3"><span id="check_file_ids">
							<c:forEach items="${files.check_files}" var="m">
								<a href="${path }/download/${m._id}.htm"
									style="margin-right: 10px;">${m.file_name} </a>
								<a
									href="javascript:delFile('${m._id }','${m.file_name}','check_file_ids')"><img
									id='idcheck_file_ids' alt='删除'
									src='${path }/style_cp/icons/httrash.gif' /> </a>
							</c:forEach>
					</span> <input type="hidden" name="check_file_ids"
						value="${apply.check_file_ids }" />
						<button type="button"
							onclick="addFiles('部门审查附件','check_file_ids')">上传附件</button>
						<button type="button"
							onclick="addScanFiles('部门审查附件','check_file_ids')">扫描上传附件</button>
					</td>
				</tr>
				<tr>
					<th align="right">法律审查附件</th>
					<td align="left" colspan="3"><span id="law_file_ids"> <c:forEach
								items="${files.law_files}" var="m">
								<a href="${path }/download/${m._id}.htm"
									style="margin-right: 10px;">${m.file_name} </a>
								<a
									href="javascript:delFile('${m._id }','${m.file_name}','law_file_ids')"><img
									id='idlaw_file_ids' alt='删除'
									src='${path }/style_cp/icons/httrash.gif' /> </a>
							</c:forEach>
					</span> <input type="hidden" name="law_file_ids"
						value="${apply.law_file_ids }" />
						<button type="button" onclick="addFiles('法律审查附件','law_file_ids')">上传附件</button>
						<button type="button" onclick="addScanFiles('法律审查附件','law_file_ids')">扫描上传附件</button>
					</td>
				</tr>
				<tr>
					<th align="right">自定义附件</th>
					<td align="left" colspan="3"><span id="self_file_ids">
							<c:forEach items="${files.self_files}" var="m">
								<a href="${path }/download/${m._id}.htm"
									style="margin-right: 10px;">${m.file_name} </a>
								<a
									href="javascript:delFile('${m._id }','${m.file_name}','self_file_ids')"><img
									id='idself_file_ids' alt='删除'
									src='${path }/style_cp/icons/httrash.gif' /> </a>
							</c:forEach>
					</span> <input type="hidden" name="self_file_ids"
						value="${apply.self_file_ids }" />
						<button type="button" onclick="addFiles('自定义附件1','self_file_ids')">上传附件</button>
						<button type="button" onclick="addScanFiles('自定义附件1','self_file_ids')">扫描上传附件</button>
					</td>
				</tr>
				<tr>
					<th align="right">自定义附件</th>
					<td align="left" colspan="3"><span id="other_file_ids">
							<c:forEach items="${files.other_files}" var="m">
								<a href="${path }/download/${m._id}.htm"
									style="margin-right: 10px;">${m.file_name} </a>
								<a
									href="javascript:delFile('${m._id }','${m.file_name}','other_file_ids')"><img
									id='idother_file_ids' alt='删除'
									src='${path }/style_cp/icons/httrash.gif' /> </a>
							</c:forEach>
					</span> <input type="hidden" name="other_file_ids"
						value="${apply.other_file_ids }" />
						<button type="button"
							onclick="addFiles('自定义附件2','other_file_ids')">上传附件</button>
						<button type="button"
							onclick="addScanFiles('自定义附件2','other_file_ids')">扫描上传附件</button>
					
					</td>
				</tr>
			</table>
			<div class="options">
				<a href="javascript:mysubmit();" class="asave">【保存】</a> <a
					href="javascript:goBack();" class="asave">【返回】</a>
			</div>
			
			<!-- 本地上传 -->
			<div id="emp" style="height: 400px;position:fixed;left:36%;top:30%;">
				<div class="query">
					<h2>
						<div>
							上传附件 <img alt="请选择申请人" src="${path }/style_cp/icons/actn011.gif"
								style="float:right" onclick="hideDiv()" />
						</div>
					</h2>
					<table width="100%" class="listlindex">
						<tr>
							<td align="right" style="padding-left: 10px;"><h3>
									<div id="msg"></div>
								</h3></td>
							<td align="center" colspan="3"
								style="padding-top: 10px;padding-left: 5px;">
								<div id="uploader-demo">
									<!--用来存放item-->
									<div id="fileList" class="uploader-list"></div>
									<div id="file_ids" onclick="getFile('other_file_ids')"></div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</div>
			
			<!-- 扫描上传 -->
			<div id="empScan" style="height: 400px;position:fixed;left:36%;top:1%;">
				<select size="1" id="source"
					style="position: relative; width: 220px;"></select> <input
					type="button" value="扫描" onclick="AcquireImage();" /> <input
					type="button" value="上传" onclick="UploadImage();" /> <span
					style="display: none;"> <label> <input type="radio"
						value="jpg" name="ImageType" id="imgTypejpeg" checked="checked" />JPEG
				</label> <label> <input type="radio" value="tif" name="ImageType"
						id="imgTypetiff" />TIFF
				</label> <label> <input type="radio" value="pdf" name="ImageType"
						id="imgTypepdf" />PDF
				</label>
				</span>


				<div id="dwtcontrolContainer"></div>

			</div>
			<jsp:include page="/WEB-INF/jsp_lib/twain.jsp" />
			
			
		</form>

	</div>
</body>
</html>